home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Turnbull China Bikeride
/
Turnbull China Bikeride - Disc 2.iso
/
STUTTGART
/
TEMP
/
GNU
/
bison
/
TokenValue
< prev
next >
Wrap
Text File
|
1995-06-28
|
1KB
|
48 lines
Token Values
Previous: <Calling Convention=>CallingCon> * Next: <Token Positions=>TokenPosit> * Up: <Lexical=>Lexical>
#Wrap on
{fH4}Semantic Values of Tokens{f}
In an ordinary (nonreentrant) parser, the semantic value of the token must
be stored into the global variable {fCode}yylval{f}. When you are using
just one data type for semantic values, {fCode}yylval{f} has that type.
Thus, if the type is {fCode}int{f} (the default), you might write this in
{fCode}yylex{f}:
#Wrap off
#fCode
…
yylval = value; \/\* Put value onto Bison stack. \*\/
return INT; \/\* Return the type of the token. \*\/
…
#f
#Wrap on
When you are using multiple data types, {fCode}yylval{f}'s type is a union
made from the {fCode}%union{f} declaration (\*Note <Union Decl=>UnionDecl>: The Collection of Value Types). So when
you store a token's value, you must use the proper member of the union.
If the {fCode}%union{f} declaration looks like this:
#Wrap off
#fCode
%union \{
int intval;
double val;
symrec \*tptr;
\}
#f
#Wrap on
then the code in {fCode}yylex{f} might look like this:
#Wrap off
#fCode
…
yylval.intval = value; \/\* Put value onto Bison stack. \*\/
return INT; \/\* Return the type of the token. \*\/
…
#f
#Wrap on